package com.ruitu.health_2.ui.mall;

import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.ruitu.arad.base.BaseActivity;
import com.ruitu.arad.support.view.NoScrollViewPager;
import com.ruitu.arad.util.SizeUtils;
import com.ruitu.health_2.R;
import com.ruitu.router_module.support.widget.BottomNavigationViewEx;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public class MallMainActivity extends BaseActivity {
    private BottomNavigationViewEx bnve;
    private NoScrollViewPager vp;

    private VpAdapter adapter;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_mall_main;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bnve = findViewById(R.id.bnve);
        vp = findViewById(R.id.vp);

        vp.setOffscreenPageLimit(9);
        vp.setScanScroll(false);

        bnve.enableAnimation(false);
        bnve.enableShiftingMode(false);
        bnve.enableItemShiftingMode(false);

        bnve.setIconsMarginTop(SizeUtils.dp2px(10));
        bnve.setIconSize(23, 23);
        bnve.setTextSize(10);
        bnve.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                return true;
            }
        });

        adapter = new VpAdapter(getSupportFragmentManager());
        vp.setAdapter(adapter);
        bnve.setupWithViewPager(vp);

        setHeadTitle("商城");
    }

    // 切换vp页面
    public void setCurrVp(int index) {
        vp.setCurrentItem(index, true);
    }

    private class VpAdapter extends FragmentPagerAdapter {

        public VpAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {// 首页
                return MallHome2Fragment.newInstance();
            } else if (position == 1) {// 分类
                return MallCategoryFragment.newInstance();
            } else if (position == 2) {// 第三个
                return Mall3Fragment.newInstance();
            } else if (position == 3) {// 第四个
                return Mall4Fragment.newInstance();
            } else if (position == 4) {// 第五个
                return Mall5Fragment.newInstance();
            }

            return MallHome2Fragment.newInstance();
        }

        @Override
        public int getCount() {
            return 5;
        }
    }
}
